# Plot legend

library(ggplot2)

unemp <- qplot(date, unemploy, data = economics, geom = "line",
               xlab = "", ylab = "No. unemployed (1000s)")
unemp

presidential <- presidential[-(1:3), ]
yrng <- range(economics$unemploy)
xrng <- range(economics$date)
unemp + geom_vline(aes(xintercept = as.numeric(start)),
                   data = presidential)

library(scales)
unemp + geom_rect(aes(NULL, NULL, xmin = start, xmax = end, fill = party),
                  ymin = yrng[1], ymax = yrng[2],
                  data = presidential, alpha = 0.2) +
  scale_fill_manual(values = c("blue", "red"))

last_plot() + geom_text(aes(x = start, y = yrng[1], label = name),
                        data = presidential, size = 3, hjust = 0, vjust = 0)

caption <- paste(strwrap("Unemployment rates in the US have varied a lot over
                         the years", 40), collapse = "\n")
unemp + geom_text(aes(x, y, label = caption), 
                  data = data.frame(x = xrng[2], y = yrng[2]),
                  hjust = 1, vjust = 1, size = 4)

highest <- subset(economics, unemploy == max(unemploy))
unemp + geom_point(data = highest, size = 3, colour = "red", alpha = 0.5)
